package com.example.interviewrecorder.manager

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.example.interviewrecorder.LyyBaseActivity

/**
 * @Description 可以监听应用内Activity的生命周期
 * @Author Yingyong Lao
 * @Date 2025/5/12 23:17
 */
object LyyAppManager {
    private const val TAG = "LyyAppManager"
    val callback:LifeCycleCallback
    init {
        callback=LifeCycleCallback()
    }
    fun registerActivityLifecycleCallbacks(application: Application){
       application.registerActivityLifecycleCallbacks(callback)
    }

    fun unRegisterActivityLifecycleCallbacks(application: Application){
        application.unregisterActivityLifecycleCallbacks(callback)
    }

    class LifeCycleCallback:Application.ActivityLifecycleCallbacks{
        override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
            if (activity !is LyyBaseActivity){
                throw RuntimeException("您的代码不符合规范，有问题的Activity为${activity::class.qualifiedName}，请将其继承自${LyyBaseActivity::class.java.name}")
            }
        }

        override fun onActivityStarted(activity: Activity) {

        }

        override fun onActivityResumed(activity: Activity) {

        }

        override fun onActivityPaused(activity: Activity) {

        }

        override fun onActivityStopped(activity: Activity) {

        }

        override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

        }

        override fun onActivityDestroyed(activity: Activity) {

        }

    }
}